package com.sinozo.utils;

/**
 * @Classname StackUtil
 * @Description 异常工具类
 * @Date 2022/8/18 14:59
 * @Created by zhehen.lu
 */
public class StackUtil {

    /**
     * @Description 转化异常错误信息
     * @Created by zhehen.lu
     * @Date 2022/8/18 15:00
     * @param e
     * @Return
     */
    public static String stackTraceToString(Exception e) {
        return stackTraceToString(e.getClass().getName(), e.getMessage(), e.getStackTrace());
    }

    /**
     * @Description 转化异常错误信息
     * @Created by zhehen.lu
     * @Date 2022/8/18 15:01
     * @param exceptionName
     * @param exceptionMessage
     * @param elements
     * @Return
     */
    public static String stackTraceToString(String exceptionName, String exceptionMessage, StackTraceElement[] elements) {
        StringBuffer strBuff = new StringBuffer();
        strBuff.append(exceptionName).append(":").append(exceptionMessage).append("\n\t");
        for (StackTraceElement stet : elements) {
            strBuff.append(stet + "\n");
        }

        return strBuff.toString();
    }
}
